package com.itheima.canal.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration

public class RabbitMQConfig {


    //交换机名称
    public static final String GOODS_UP_EXCHANGE ="goods_up_exchange";
    public static final String GOODS_DOWN_EXCHANGE="goods_down_exchange";
    //定义队列名称
    private static final String SEARCH_ADD_QUEUE = "search_add_queue";
    public static final String SEARCH_DEL_QUEUE="search_del_queue";
    public static final String AD_UPDATE_QUEUE = "ad_update_queue";
    public static final String PAGE_CREATE_QUEUE="page_create_queue";

    //声明队列
    @Bean
    public Queue queue() {
        return new Queue(AD_UPDATE_QUEUE);
    }

    //声明队列
    @Bean
    public Queue search_add_queue() {
        return new Queue(SEARCH_ADD_QUEUE);
    }
    @Bean
    public Queue search_del_queue() {
        return new Queue(SEARCH_DEL_QUEUE);
    }
    @Bean
    public Queue page_create_queue() {
        return new Queue(PAGE_CREATE_QUEUE);
    }

    //声明交换机
    @Bean
    public Exchange goods_up_exchange() {
        return ExchangeBuilder.fanoutExchange(GOODS_UP_EXCHANGE).durable(true).build();
    }
    @Bean
    public Exchange goods_down_exchange() {
        return ExchangeBuilder.fanoutExchange(GOODS_DOWN_EXCHANGE).durable(true).build();
    }

    //队列与交换机绑定
    @Bean
    public Binding GOODS_UP_EXCHANGE_BINDING(Queue search_add_queue, Exchange goods_up_exchange) {
        return BindingBuilder.bind(search_add_queue).to(goods_up_exchange).with("").noargs();
    }
    @Bean
    public Binding PAGE_CREATE_QUEUE_BINDING(Queue page_create_queue, Exchange goods_up_exchange) {
        return BindingBuilder.bind(page_create_queue).to(goods_up_exchange).with("").noargs();
    }
    @Bean
    public Binding GOODS_DOWN_EXCHANGE_BINDING(Queue search_del_queue, Exchange goods_down_exchange) {
        return BindingBuilder.bind(search_del_queue).to(goods_down_exchange).with("").noargs();
    }
}
